/*
 * Copyright (C) 2008 Peter Kling
 * 
 * This file is part of 'A Kind of Billiard', a graphical billiard simulation.
 * 
 * 'A Kind of Billiard' is free software: you can redistribute it and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * 'A Kind of Billiard' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with 'A Kind of Billiard'. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package de.akob.mathematics;

/**
 * A cuboid. Provides basic methods as for example testing whether a given point lies inside the cuboid. Note that
 * cuboids are considered as closed objects.
 */
public class Cuboid {
	private final double xMin, xMax, yMin, yMax, zMin, zMax;
	private final double width, height, depth;
	
	/**
	 * Creates a new cuboid using the given coordinates.
	 * 
	 * @param values coordinates in following order: xmin, xmax, ymin, ymax, zmin, zmax
	 */
	public Cuboid(double... values) {
		if (values.length != 6)
			throw new IllegalArgumentException("cuboid must be given by exactly 6 double values");
		this.xMin = values[0];
		this.xMax = values[1];
		this.yMin = values[2];
		this.yMax = values[3];
		this.zMin = values[4];
		this.zMax = values[5];
		this.width = xMax - xMin;
		this.height = yMax - yMin;
		this.depth = zMax - zMin;
	}
	
	/**
	 * Returns whether the given three dimensional point is contained in the cuboid.
	 * 
	 * @param v three dimensional point that is checked for
	 * @return whether the given point is contained in the cuboid
	 */
	public boolean contains(MathVector v) {
		if (v.get(1) < xMin || v.get(1) > xMax || v.get(2) < yMin || v.get(2) > yMax || v.get(3) < zMin
		        || v.get(3) > zMax)
			return false;
		return true;
	}
	
	/**
	 * Returns the depth (z-direction) of the cuboid.
	 * 
	 * @return depth of the cuboid
	 */
	public double getDepth() {
		return depth;
	}
	
	/**
	 * Returns the height (y-direction) of the cuboid.
	 * 
	 * @return height of the cuboid
	 */
	public double getHeight() {
		return height;
	}
	
	/**
	 * Returns maximal x coordinate.
	 * 
	 * @return maximal x coordinate
	 */
	public double getMaxX() {
		return xMax;
	}
	
	/**
	 * Returns maximal y coordinate.
	 * 
	 * @return maximal y coordinate
	 */
	public double getMaxY() {
		return yMax;
	}
	
	/**
	 * Returns maximal z coordinate.
	 * 
	 * @return maximal z coordinate
	 */
	public double getMaxZ() {
		return zMax;
	}
	
	/**
	 * Returns minimal x coordinate.
	 * 
	 * @return minimal x coordinate
	 */
	public double getMinX() {
		return xMin;
	}
	
	/**
	 * Returns minimal y coordinate.
	 * 
	 * @return minimal y coordinate
	 */
	public double getMinY() {
		return yMin;
	}
	
	/**
	 * Returns minimal z coordinate.
	 * 
	 * @return minimal z coordinate
	 */
	public double getMinZ() {
		return zMin;
	}
	
	/**
	 * Returns the width (x-direction) of the cuboid.
	 * 
	 * @return width of the cuboid
	 */
	public double getWidth() {
		return width;
	}
}
